#coding:utf-8

class Vector(list):

    # 初始化
    def __init__(this,*arg):
        for v in list(arg):
            this.append(v)

    # 矢量数乘
    def mul(this,times):
        for i in range(0,len(this)):
            this[i] *= times
        return this

    # 矢量加和
    def addVector(this,vec):
        l = len(vec)
        if l != len(this):
            raise ValueError('不一致的矢量维度')
        for i in range(0,l):
            this[i] += vec[i]
        return this

    # 加减某一数值
    def add(this,value):
        this.addVector([value] * len(this))
        return this

    # 矢量的数积
    def product(this,vec):
        l = len(vec)
        if l != len(this):
            raise ValueError('不一致的矢量维度')

        s = sum(map(
                lambda i:this[i] * vec[i],
                range(0,l)
                ))
        return s



# 测试脚本
def test():
    v1 = Vector(1,2,3)
    v2 = Vector(1,2,3)
    print(v1.product(v2));
    print(isinstance(v1,Vector))
    pass

if __name__=='__main__':
    import sys
    test()